package com.taoym.voucher.admin.controller;

import com.taoym.voucher.common.response.Response;
import com.taoym.voucher.admin.entity.dto.SysAddActivityDTO;
import com.taoym.voucher.admin.entity.vo.SysGetSysActivitiesVO;
import com.taoym.voucher.admin.service.SysActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/7/22 11:39
 * @desc 系统活动控制器
 */
@RestController
@RequestMapping("/sys/activity")
@Api(tags = "系统活动控制器")
public class SysActivityController {

    @Autowired
    private SysActivityService sysActivityService;

    @ApiOperation("查询所有活动信息")
    @GetMapping("/list")
    public Response<List<SysGetSysActivitiesVO>> listActivities() {
        return Response.success(sysActivityService.getSysActivities());
    }

    @ApiOperation("添加系统活动信息")
    @PostMapping("/add")
    public Response<Integer> addSysActivity(@RequestBody @Valid SysAddActivityDTO data) {
        return Response.success(sysActivityService.addSysActivity(data));
    }

    @ApiOperation("删除系统活动信息")
    @PostMapping("/delete")
    public Response<Integer> deleteSysActivity(@RequestParam("id") @NotNull(message = "活动编号不能为空") Integer id) {
        return Response.success(sysActivityService.deleteSysActivity(id));
    }

    @ApiOperation("同步活动")
    @GetMapping("/sync")
    public Response<Integer> syncAct() {
        return Response.success(sysActivityService.syncAct());
    }
}
